package com.book.controller;

import com.book.config.SystemConfig;
import com.book.service.TbBookService;
import com.book.param.BookAdd;
import com.book.vo.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (TbBook)表控制层
 *
 * @author makejava
 * @since 2024-11-07 19:53:25
 */
@RestController
@RequestMapping("api/tbBook")
@Slf4j
@Tag(name = "图书模块")
public class TbBookController{
    /**
     * 服务对象
     */
    @Resource
    private TbBookService service;

    @Operation(summary = "查询书籍")
    @GetMapping("/find")
    public R getBookList(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "50")Integer pageSize,
                         String bookName){
        return service.getBookList(page,pageSize,bookName);
    }
    @Operation(summary = "查询单个书籍")
    @GetMapping("/findBook")
    public R getBook(String bookName){
            return service.getBook(bookName);
    }

    @PostMapping("/addBook")
    public R addBook(@RequestBody BookAdd bookAdd){
        System.out.println(bookAdd.toString());
        return R.ok(null);
    }


    @Operation(summary = "下架书籍")
    @GetMapping("/deleteBook")
    public R deleteBook(HttpServletRequest request,Integer bookId){
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        return service.deleteBook(token,bookId);
    }


}

